package inbound.po.dataObjects
{
	import common.utils.DateManager;
	
	import mx.collections.ArrayCollection;
	[Bindable]
	public class POHeaderDO
	{
		public var INTERNAL_PURCHASE_ORDER_NUM:Number = 0;
		public var WAREHOUSE:String = "";
		public var COMPANY:String = "";
		public var PURCHASE_ORDER_ID:String = "";
		public var PURCHASE_ORDER_TYPE:String = "";
		public var CLOSE_DATE:String = DateManager.GetTodayString();
		public var PRIORITY:Number = 10;
		public var STATUS:String = "100";
		public var ERP_ORDER_ID:String = "";
		public var SHIP_FROM:String = "";
		public var SHIP_FROM_ADDRESS1:String = "";
		public var SHIP_FROM_ADDRESS2:String = "";
		public var SHIP_FROM_CITY:String = "";
		public var SHIP_FROM_STATE:String = "";
		public var SHIP_FROM_COUNTRY:String = "";
		public var SHIP_FROM_POSTAL_CODE:String = "";
		public var SHIP_FROM_NAME:String = "";
		public var SHIP_FROM_ATTENTION_TO:String = "";
		public var SHIP_FROM_EMAIL_ADDRESS:String = "";
		public var SHIP_FROM_PHONE_NUM:String = "";
		public var SHIP_FROM_FAX_NUM:String = "";		
		public var SCHEDULED_ARRIVE_DATE:String = DateManager.GetTodayString();
		public var ACTUAL_ARRIVE_DATE:String = DateManager.GetTodayString();
		public var USER_STAMP:String = "";
		public var DATE_TIME_STAMP:String = DateManager.GetTodayString();;
		
		public function POHeader():void
		{
		}

		public function Init(xmlObj:XML):void
		{
			if(null == xmlObj)
				return;
			else{
				for each (var itemProp:XML in xmlObj.children()) {
					//Use XML node name to reference matching property in value object				
					this[itemProp.name()] = itemProp;
				}
			}
		}
		
		public function ToXML():XML{
			var xmlObj:XML = 
				<PURCHASE_ORDER_HEADER>
					<INTERNAL_PURCHASE_ORDER_NUM>{INTERNAL_PURCHASE_ORDER_NUM}</INTERNAL_PURCHASE_ORDER_NUM>
					<WAREHOUSE>{WAREHOUSE}</WAREHOUSE>
					<COMPANY>{COMPANY}</COMPANY>
					<PURCHASE_ORDER_ID>{PURCHASE_ORDER_ID}</PURCHASE_ORDER_ID>
					<PURCHASE_ORDER_TYPE>{PURCHASE_ORDER_TYPE}</PURCHASE_ORDER_TYPE>
					<CLOSE_DATE>{CLOSE_DATE}</CLOSE_DATE>
					<PRIORITY>{PRIORITY}</PRIORITY>
					<STATUS>{STATUS}</STATUS>
					<ERP_ORDER_ID>{ERP_ORDER_ID}</ERP_ORDER_ID>
					<SHIP_FROM>{SHIP_FROM}</SHIP_FROM>
					<SHIP_FROM_ADDRESS1>{SHIP_FROM_ADDRESS1}</SHIP_FROM_ADDRESS1>
					<SHIP_FROM_ADDRESS2>{SHIP_FROM_ADDRESS2}</SHIP_FROM_ADDRESS2>
					<SHIP_FROM_CITY>{SHIP_FROM_CITY}</SHIP_FROM_CITY>
					<SHIP_FROM_STATE>{SHIP_FROM_STATE}</SHIP_FROM_STATE>
					<SHIP_FROM_COUNTRY>{SHIP_FROM_COUNTRY}</SHIP_FROM_COUNTRY>
					<SHIP_FROM_POSTAL_CODE>{SHIP_FROM_POSTAL_CODE}</SHIP_FROM_POSTAL_CODE>
					<SHIP_FROM_NAME>{SHIP_FROM_NAME}</SHIP_FROM_NAME>
					<SHIP_FROM_ATTENTION_TO>{SHIP_FROM_ATTENTION_TO}</SHIP_FROM_ATTENTION_TO>
					<SHIP_FROM_EMAIL_ADDRESS>{SHIP_FROM_EMAIL_ADDRESS}</SHIP_FROM_EMAIL_ADDRESS>
					<SHIP_FROM_PHONE_NUM>{SHIP_FROM_PHONE_NUM}</SHIP_FROM_PHONE_NUM>
					<SHIP_FROM_FAX_NUM>{SHIP_FROM_FAX_NUM}</SHIP_FROM_FAX_NUM>
				</PURCHASE_ORDER_HEADER>;
			return xmlObj;
		}
		
		public static function getPOHeaders(list:XMLList):ArrayCollection
		{
			var ac:ArrayCollection = new ArrayCollection();
			for each(var xml:XML in list)
			{
				var poHdr:POHeaderDO = new POHeaderDO();
				poHdr.Init(xml);
				ac.addItem(poHdr);
			}
			return ac;
		}						
	}
}